package com.cjy.menu.service.impl;

import com.base.common.persistent.dao.TAppMenuCompoundsMapper;
import com.base.common.persistent.dao.TAppMenuMapper;
import com.base.common.persistent.model.TAppMenuCompounds;
import com.base.common.persistent.model.TAppMenuCompoundsExample;
import com.base.common.persistent.model.TAppMenuExample;
import com.cjy.menu.service.MenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by Kevin on 2017-9-12.
 */
@Service("menuService")
public class MenuServiceImpl implements MenuService {

     @Resource
     private TAppMenuMapper tAppMenuMapper;

    @Resource
    private TAppMenuCompoundsMapper tAppMenuCompoundsMapper;

    @Override
    public Object queryMenu(int bid, int compoundsId) {
        TAppMenuCompoundsExample tAppMenuCompoundsExample = new TAppMenuCompoundsExample();
        tAppMenuCompoundsExample.createCriteria().andCompoundsIdEqualTo((long) compoundsId);
        List<Long> menuIds = tAppMenuCompoundsMapper.selectByExample(tAppMenuCompoundsExample).stream().collect(Collectors.mapping(TAppMenuCompounds::getMenuId, Collectors.toList()));
        if (menuIds.size() == 0) {
            return null;
        }
        TAppMenuExample tAppMenuExample = new TAppMenuExample();
        tAppMenuExample.createCriteria().andAppFlagEqualTo(bid).andIdIn(menuIds);
        return tAppMenuMapper.selectByExample(tAppMenuExample);
    }
}
